<?php

namespace App\Admin\Repositories;

use Dcat\Admin\Repositories\EloquentRepository;
use App\Models\CompanyManagement as CompanyManagementModel;

class CompanyManagement extends EloquentRepository
{

    public $model;

    public function __construct()
    {
        $this->model = new CompanyManagementModel();
    }


    /**
     * @param int $management_id
     * @param array $company
     * @return bool
     */
    public function setData(int $management_id, array $company)
    {
        $re_del = $this->model->where('management_id', $management_id)->delete();
        $company = array_filter($company);
        if($company) {
            $insert_data = [];
            foreach ($company as $company_id) {
                $insert_data[] = [
                    'management_id' => $management_id,
                    'company_id' => $company_id,
                ];
            }
            $re_insert = $this->model->insert($insert_data);
        }
        return true;

    }

}
